package com.example.demo_text;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class QuestionDAO {
    public static List<Question> getQuestionsByCourseId(String courseId) {
        List<Question> questions = new ArrayList<>();
        String sql = "SELECT * FROM question WHERE course_id = ?";

        try (Connection conn = UserDAO.getConnection();
             PreparedStatement stmt = conn.prepareStatement(sql)) {

            stmt.setString(1, courseId);
            ResultSet rs = stmt.executeQuery();

            while (rs.next()) {
                Question question = new Question(
                        rs.getInt("question_id"),
                        rs.getString("course_id"),
                        rs.getString("question_content"),
                        rs.getString("teacher_id")
                );
                questions.add(question);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

        return questions;
    }
}
